export type Test2Point = {
  init: () => void;
  points: { id: number; longitude: number; latitude: number }[];
  test: () => void;
  end: () => void;
};

export const test2Point = (map: mapboxgl.Map | null) => {
  const init = () => {
    map?.addSource('two-ptns', {
      type: 'geojson',
      data: {
        type: 'FeatureCollection',
        features: [],
      },
    });
    map?.addLayer({
      id: 'two-ptns',
      type: 'circle',
      source: 'two-ptns',
    });
  };

  const points = [
    {
      id: 1,
      longitude: 113.2644,
      latitude: 23.1291,
    },
    {
      id: 2,
      longitude: 113.2744,
      latitude: 23.1391,
    },
  ];

  // GeoJSON.FeatureCollection<GeoJSON.Point>
  const featureCollection = {
    type: 'FeatureCollection',
    features: [
      {
        type: 'Feature',
        geometry: { type: 'Point', coordinates: [113.2644, 23.1291] },
        properties: {},
      },
      {
        type: 'Feature',
        geometry: { type: 'Point', coordinates: [113.2744, 23.1391] },
        properties: {},
      },
    ],
  } as GeoJSON.FeatureCollection<GeoJSON.Point>;

  const test = () => {
    // 假设已有目标点数据（如从GeoJSON或API获取）
    // 将这两个点绘制到地图上
    const source = map?.getSource('two-ptns') as mapboxgl.GeoJSONSource;
    source?.setData?.({
      type: 'FeatureCollection',
      features: featureCollection.features,
    });
  };

  const end = () => {
    map?.removeSource('two-ptns');
    map?.removeLayer('two-ptns');
  };

  return { init, points, test, end };
};
